package com.song.util;

import com.song.base.consts.ResponseEnum;
import com.song.base.exception.HeaderException;
import lombok.extern.slf4j.Slf4j;

import java.security.MessageDigest;
import java.util.Base64;

@Slf4j
public class PassUtil {
    public static String PasssWitch(String pass){
        String md5Str=null;
        try {
            MessageDigest md5 = MessageDigest.getInstance("MD5");

            Base64.Encoder encoder = Base64.getEncoder();
            md5Str = encoder.encodeToString(md5.digest(pass.getBytes("utf-8")));
        }catch (Exception e){
            log.info("密码转化异常：{}",pass);
            throw new HeaderException("密码转换错误",ResponseEnum.Transform__FLOW.getCode());
        }
        return md5Str;
    }
}
